#!/usr/bin/env python

# Imports:
# -------
import wx
from rubber_band import RubberBand

# --------------------------
class LabelerPanel(wx.Panel):
# --------------------------
	# ------------------------
	def __init__(self, parent):
	# ------------------------
		wx.Panel.__init__(self, parent=parent)

		# Create the sizer
		self.sizer = wx.BoxSizer(wx.VERTICAL)
		self.SetSizer(self.sizer)
		self.sizer.AddSpacer(10)

		# Load the default images
		self.home = wx.Image('resources/home.png', wx.BITMAP_TYPE_PNG)
		self.home = wx.BitmapFromImage(self.home)
		self.rubberBand = RubberBand(self.home, self)
		self.sizer.Add(self.rubberBand, 3, wx.EXPAND)

		self.loadingBag = wx.BitmapFromImage(wx.Image('resources/loading_bag.png', wx.BITMAP_TYPE_PNG))
		self.generatingAnnotations = wx.BitmapFromImage(wx.Image('resources/generating_annotations.png', wx.BITMAP_TYPE_PNG))
		self.generatingAnnotations = wx.BitmapFromImage(wx.Image('resources/generating_annotations.png', wx.BITMAP_TYPE_PNG))
		

		# Add Text fields for the paramaters
		self.stringParamSizer = wx.BoxSizer(wx.HORIZONTAL)
		self.nameLabel = wx.StaticText(self, label='Name:')
		self.stringParamSizer.Add(self.nameLabel, 0, wx.LEFT)
		self.stringParamSizer.AddSpacer(5)
		self.nameField = wx.TextCtrl(self)
		self.stringParamSizer.Add(self.nameField, 1, wx.EXPAND)
		self.stringParamSizer.AddSpacer(5)
		self.orientationCombo = wx.ComboBox(self, wx.ID_ANY, value = 'Front', choices = ('Front', 'Profile'))
		self.stringParamSizer.Add(self.orientationCombo, 0, wx.RIGHT)
		self.sizer.Add(self.stringParamSizer, 0, wx.EXPAND)
		
		# Add the timeline control
		self.slider = wx.Slider(self, wx.ID_ANY, 0, 0, 100, style = wx.SL_HORIZONTAL)
		self.sizer.Add(self.slider, 0, wx.EXPAND)

		# Add the VCR controls
		self.leftRightSizer = wx.BoxSizer(wx.HORIZONTAL)
		self.leftButton = wx.Button(self, wx.ID_ANY, 'Previous')
		self.leftRightSizer.Add(self.leftButton, 0, wx.CENTER)
		self.frameText = wx.StaticText(self, label='  (No bag loaded)  ')
		self.leftRightSizer.Add(self.frameText, 0, wx.CENTER)
		self.rightButton = wx.Button(self, wx.ID_ANY, 'Next')
		self.leftRightSizer.Add(self.rightButton, 0, wx.CENTER)
		self.sizer.Add(self.leftRightSizer, 0, wx.CENTER)
		self.sizer.AddSpacer(10)
		self.Layout()

		# Create ther rubber bander

		self.Disable()

	# ---------------------------------------
	def setRubberBandCallback(self, callback):
	# ---------------------------------------
		self.rubberBand.setCallback(callback)

	# -----------------------
	def setImage(self, image):
	# -----------------------
		self.rubberBand.setImage(image)

	# -------------------------------
	def displayProgress(self, i, tot):
	# -------------------------------
		# Update the label
		self.frameText.SetLabel('  (%i/%i)  ' % (i, tot))

		# Update the slider
		self.slider.SetMax(tot)
		self.slider.SetValue(i)
		self.Layout()

	# --------------
	def Enable(self):
	# --------------
		self.enableVCR()
		self.enableLabeler()		

	# -----------------
	def enableVCR(self):
	# -----------------
		self.leftButton.Enable()
		self.rightButton.Enable()
		self.frameText.Enable()
		self.slider.Enable()

	# ---------------------
	def enableLabeler(self):
	# ---------------------
		self.rubberBand.Enable()
		self.orientationCombo.Enable()
		self.nameField.Enable()
		self.nameLabel.Enable()

	# ---------------
	def Disable(self):
	# ---------------
		self.disableVCR()
		self.disableLabeler()		

	# ------------------
	def disableVCR(self):
	# ------------------
		self.leftButton.Disable()
		self.rightButton.Disable()
		self.frameText.Disable()
		self.slider.Disable()

	# ----------------------
	def disableLabeler(self):
	# ----------------------
		self.rubberBand.Disable()
		self.orientationCombo.Disable()
		self.nameField.Disable()
		self.nameLabel.Disable()
